<template>
  <el-dialog v-if="load" title="新增" v-model="visible" align-center width="800px" @close="handleClose" :close-on-click-modal="false">
    <el-form>
      <el-form-item label="title">
        <el-input />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" :loading="loadings.submit" @click="submit">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import api from '../api'
import { ElMessage } from 'element-plus'
const load = ref(false)
const visible = ref(false)
let loadings = reactive({})

const emit = defineEmits(['close'])

// 打开弹窗
const open = async (selection) => {
  if (selection && !selection.length) {
    ElMessage.warning('请先选择行!')
    return
  }
  if (!load.value) {
    load.value = true
    await 1
  }
  loadings = reactive({})
  visible.value = true
}
// 关闭弹窗
const close = () => {
  visible.value = false
}

const handleClose = () => {
  emit('close')
}
// 提交
const submit = () => {
  loadings.submit = true
  api.submit().then(res => {
    close()
  }).finally(() => {
    loadings.submit = false
  })
}

defineExpose({ open })
</script>